Conversation
froydnj
approved these changes
Jan 1, 2026
Collaborator
froydnj
left a comment
There was a problem hiding this comment.
Oh man, I thought this was going to have to wait until the ripper backend was gone. So nice.
e3a9a0b to
d07e1c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The biggest remaining source of unnecessary String allocations is simple constants like identifiers that come from source code. Since historically we haven't operated by references (since we had to copy all the Ripper objects) back to source nodes, most of the main structs (
ParserStateetc.) don't have clear lifetimes, forcing most of our render tokens to operate entirely on owned Strings.This PR is a bit invasive but ultimately relatively straightforward: it adds a
'srclifetime, adds it throughout all of the structs and functions that operate on Prism nodes or tokens, and then updates places to use{loc,const}_to_strwherever possible. This means we no longer need to clone identifiers or convert them to strings, including in some of the associated machinery (e.g. variable bindings).It's probably easiest to review this commit-by-commit. The first commit mostly adds lifetimes to structs, the second to formatting functions, and the last converts
*_to_stringto*_to_strwherever possible. It's possible this same thing could be applied to other callers (Strings, heredoc closers, etc.) but for the sake of minimizing the change I've punted on those for later.